package edu.hnnu.sport_event.utils;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;

import java.io.OutputStream;

public class ValidationCode {

    /**
     * 生成验证码并写入到输出流中
     * @param out 输出流OutputStream
     * @return 验证码
     */
    public static String getValidationCode(OutputStream out) {
        RandomGenerator generator = new RandomGenerator("01233456789", 4);
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(100, 24);
        captcha.setGenerator(generator);
        String code = captcha.getCode();
        captcha.write(out);
        return code;
    }

}
